#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QMouseEvent>
#include <QGraphicsDropShadowEffect>
#include <QDebug>
#include <QJsonObject>
#include <QJsonArray>
#include "lrcform.h"
#include "qmediaplayer.h"
#include "qpropertyanimation.h"
#include "qsystemtrayicon.h"
#include "rightform.h"
#include "volumeform.h"
#include "listform.h"
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QSqlError>
#include <QMessageBox>

QT_BEGIN_NAMESPACE
namespace Ui {
class Widget;
}
QT_END_NAMESPACE

class Widget : public QWidget
{
    Q_OBJECT

public:
    Widget(QWidget *parent = nullptr);
    ~Widget();

    //初始ui
    void initUi();

    //初始化信号槽
    void initConnect();

    //初始化数据库
    bool initDB();

    //初始化历史关闭列表
    void initData();

    //窗口移动
    void mousePressEvent(QMouseEvent *event);
    void mouseMoveEvent(QMouseEvent *event);

    //设置窗口美化
    void setupShadow();

    //设置推荐文本及图片
    QJsonArray setRecImgAndText();

    //初始化媒体播放
    void initPlay();
    //初始化播放页列表
    void initMusicList();

private slots:
    void addSystemAction();
    void on_exit_clicked();
    void onRbtnClicked();
    void onMaxClicked();
    void onMinClicked();
    void rightPageChange(int pageIndex);

    void on_volume_clicked();

    //更新喜欢界面
    void upDatePageOfLike(bool isLike, QString itemid);

    //播放器信号槽
    void onDdurationChanged(qint64 duration);
    void onPositionChanged(qint64 duration);
    void onStateChanged();
    void onFrameSetValueClicked(float num);
    void onMetaDataAvailableChanged(bool available);
    void onPlayClicked();
    void onPlayPreClicked();
    void onPlayNextClicked();
    void onPlayAllClicked(Page Page);
    void onVolumeClicked();
    void onPlayTypeClicked();
    void showLrcPage();
    void setMusicPage(rightForm* page);
    void curPlayChanged(int index);
    void playPageByIndex(rightForm* page, const int index);

    void upDateAnimation();

    void on_skin_clicked();


    void on_setting_clicked();

private:
    Ui::Widget *ui;
    QSqlDatabase db;
    QPoint relpos;
    volumeForm* volume;
    listForm musiclist;
    QMediaPlayer* player;
    QMediaPlaylist* playlist;
    qint64 onduration;
    Page Pagetype;
    rightForm* curPage;
    lrcForm* lrc;
    int curindex;
    QPropertyAnimation* lrcAnimetion;
    bool notMove;
    bool durationSet;
    bool color;
    QSystemTrayIcon* TrayIcon;
};
#endif // WIDGET_H
